{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Processing Example"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"from fibermagic.IO.NeurophotometricsIO import read_project_rawdata, read_project_logs\n",
"from pathlib import Path\n",
"import plotly.express as px\n",
"from fibermagic.core.demodulate import zdFF_airPLS, add_zdFF\n",
"from fibermagic.core.perievents import perievents\n",
"from fibermagic.utils.download_dataset import download"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading started\n",
"Downloading Completed, Extracting...\n"
]
}
],
"source": [
"download('arena-data')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The data was taken in two batches from different mice. Batch 1 consists of one recording per mouse (n=2). Batch 2 includes two recordings per mouse (n=7). Every mouse was recorded individually (no multiple mice per recording).\n",
"\n",
"The experimental environment was a 1m x 1m sized arena. The mouse was able to move freely. Food pellets, a running wheel, and a novel object was placed in different locations of the arena. Sessions were 15 minutes long.\n",
"\n",
"For behavioral evaluation, a video was recorded using a IR-camera. The video was used to determing the region in which the mouse was."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"data\\Batch 1\\Day1\\FP\\B9295\\arena.csv\n",
"data\\Batch 1\\Day1\\FP\\B9296\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9443\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9670\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9671\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9888\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9889\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9890\\arena.csv\n",
"data\\Batch 2\\Day1\\FP\\B9891\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9443\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9670\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9671\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9888\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9889\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9890\\arena.csv\n",
"data\\Batch 2\\Day2\\FP\\B9891\\arena.csv\n"
]
}
],
"source": [
"PROJECT_PATH = Path(r'data')\n",
"df_idx = read_project_rawdata(PROJECT_PATH,\n",
" ['Batch', 'Day', 'FP', 'Mouse_'], 'arena.csv', ignore_dirs=['meta', 'processed', 'processed.zip'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A first spike into to investigate the raw data.\n",
"\n",
"By changing values to different mice and days, you can see that mice B9671 and B9889 had bad signals."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['B9295', 'B9296', 'B9443', 'B9670', 'B9671', 'B9888', 'B9889',\n",
" 'B9890', 'B9891'], dtype=object)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = df_idx.reset_index()\n",
"df.Mouse.unique() # list recorded mice"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "variable=Signal
index=%{x}
value=%{y}
\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | Signal | \n", "Reference | \n", "zdFF (airPLS) | \n", "
---|---|---|---|---|---|---|---|---|---|
Batch | \n", "Day | \n", "FP | \n", "Mouse_ | \n", "Mouse | \n", "Channel | \n", "FrameCounter | \n", "\n", " | \n", " | \n", " |
Batch 1 | \n", "Day1 | \n", "FP | \n", "B9295 | \n", "B9295 | \n", "470 | \n", "201 | \n", "0.006334 | \n", "0.004026 | \n", "-0.138428 | \n", "
202 | \n", "0.006327 | \n", "0.004017 | \n", "-0.138428 | \n", "||||||
203 | \n", "0.006363 | \n", "0.004003 | \n", "-0.258778 | \n", "||||||
204 | \n", "0.006339 | \n", "0.004004 | \n", "-0.359795 | \n", "||||||
205 | \n", "0.006374 | \n", "0.004003 | \n", "-0.461999 | \n", "||||||
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
Batch 2 | \n", "Day2 | \n", "FP | \n", "B9891 | \n", "B9891 | \n", "560 | \n", "23482 | \n", "0.005995 | \n", "0.004768 | \n", "-0.297719 | \n", "
23483 | \n", "0.005960 | \n", "0.004758 | \n", "-0.276701 | \n", "||||||
23484 | \n", "0.006041 | \n", "0.004695 | \n", "-0.097237 | \n", "||||||
23485 | \n", "0.005952 | \n", "0.004757 | \n", "-0.187640 | \n", "||||||
23486 | \n", "0.006012 | \n", "0.004762 | \n", "-0.384082 | \n", "
735342 rows × 3 columns
\n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | Frame | \n", "Event | \n", "Timestamp | \n", "
---|---|---|---|---|---|---|---|---|
Batch | \n", "Day | \n", "FP | \n", "Mouse_ | \n", "Mouse | \n", "FrameCounter | \n", "\n", " | \n", " | \n", " |
Batch 1 | \n", "Day1 | \n", "FP | \n", "B9295 | \n", "B9295 | \n", "2522 | \n", "2717 | \n", "non_roi_out | \n", "90.566667 | \n", "
2523 | \n", "2718 | \n", "food_in | \n", "90.600000 | \n", "|||||
2572 | \n", "2777 | \n", "food_out | \n", "92.566667 | \n", "|||||
2573 | \n", "2778 | \n", "non_roi_in | \n", "92.600000 | \n", "|||||
2578 | \n", "2784 | \n", "non_roi_out | \n", "92.800000 | \n", "|||||
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
Batch 2 | \n", "Day2 | \n", "FP | \n", "B9891 | \n", "B9891 | \n", "20104 | \n", "23044 | \n", "non_roi_in | \n", "768.133333 | \n", "
20118 | \n", "23061 | \n", "non_roi_out | \n", "768.700000 | \n", "|||||
20119 | \n", "23062 | \n", "wheel_in | \n", "768.733333 | \n", "|||||
20183 | \n", "23139 | \n", "wheel_out | \n", "771.300000 | \n", "|||||
20184 | \n", "23140 | \n", "non_roi_in | \n", "771.333333 | \n", "
3008 rows × 3 columns
\n", "